package com.smxy.mall.service.impl;

import com.smxy.mall.dao.SwiperDao;
import com.smxy.mall.entity.Swiper;
import com.smxy.mall.model.request.SwiperReq;
import com.smxy.mall.service.SwiperService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;
@Service
public class SwiperServicelmpl implements SwiperService {
    @Resource
    private SwiperDao swiperDao;

    @Override
    public List<Swiper> list(SwiperReq swiperReq) {
       return swiperDao.findByShopIdAndPosition(swiperReq.getShopId(),swiperReq.getPosition());
    }

    @Override
    public Swiper save(SwiperReq swiperReq) {
        Swiper swiper = new Swiper();
        swiper.setImg(swiperReq.getImg());
        swiper.setStatus(swiperReq.getStatus());
        swiper.setPosition(swiperReq.getPosition());
        swiper.setShopId(swiperReq.getShopId());
        swiper.setLink(swiperReq.getLink());
        swiper.setLinkType(swiperReq.getLinkType());
        if(!StringUtils.isEmpty(swiperReq.getId())){
            swiper.setId(swiperReq.getId());
        }
        return swiperDao.save(swiper);
    }
}
